/**
 * 
 */
package com.local.guava.splitter;

import com.google.common.base.Splitter;

/**
 * @author admin
 *
 */
public class SplitterMethod {

	private static final String STR = "a,,b,  c";
	
	public void jdkSplit(){
		String[] s = STR.split(",");
        for(int i=0; i < s.length; i++) {
       	 System.out.print(s[i]);
        }
        System.out.println("");
	}
	
	
	/**
	 *    omitEmptyStrings()	          从结果中自动忽略空字符串
     *    trimResults()	                              移除结果字符串的前导空白和尾部空白
     *    trimResults(CharMatcher)	给定匹配器，移除结果字符串的前导匹配字符和尾部匹配字符
     *    limit(int)	                               限制拆分出的字符串数量
	 */
	
	public void guavaSplit(){
		Iterable<String> it = Splitter.on(',')
		.trimResults()
		.omitEmptyStrings()
		.limit(4)
		.split(STR);
         System.out.println(it);
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		SplitterMethod sp = new SplitterMethod();
		sp.jdkSplit();
        sp.guavaSplit();
	}

}
